/**
 * @author caesar
 * @date 2025/7/1
 * @apiNote
 */
//冒泡排序
public class bubbleSort {
    public static void main(String[] args) {
        //int[] arr = {5, 3, 2, 1, 4};
        int[] arr = {1, 2, 3, 5,4};
        boolean flag = false;
        for (int i = 1; i < arr.length; i++) {//循环轮数
            for (int j = 0; j < arr.length - i; j++) {
                flag = false;
                if (arr[j] > arr[j + 1]) {
                    int t = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = t;
                    flag = true;
                }
            }
            if (flag) {
                break;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
